package com.liu.efk.service.impl;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.efk.domain.Duser;
import com.liu.efk.mapper.DuserMapper;
import com.liu.efk.service.IDuserService;

import com.liu.efk.utils.PageUtils;
import com.liu.efk.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Transactional
@Service
public class DuserServiceImpl extends ServiceImpl<DuserMapper, Duser> implements IDuserService {

    @Autowired
    RedisTemplate redisTemplate;

    public Map getUserVOList(int num , int rows) {

        List<UserVO>  listUser = new ArrayList<>();
        Page<Duser> pages =new Page(num,rows);

       this.page(pages,null);



        pages.getRecords().forEach(e->{
            UserVO user = new UserVO();
            BeanUtils.copyProperties(e,user);
            String name = (String) redisTemplate.opsForValue().get("project_"+e.getCodeProject());
            user.setProjectName(name);
            String roleName = (String) redisTemplate.opsForValue().get("role_"+e.getRoleId());
            user.setRoleName(roleName);
            String userName = (String) redisTemplate.opsForValue().get("users_"+e.getCodeUsrAccount());
            user.setUserName(userName);

            listUser.add(user);
        });



        return  PageUtils.getResultMap(pages.getTotal(), listUser);
    }

}
